﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.BaseInformation;


namespace TyMES.ViewModel.BaseInformation.DqOrderVMs
{
    public partial class DqOrderListVM : BasePagedListVM<DqOrder_View, DqOrderSearcher>
    {

        protected override IEnumerable<IGridColumn<DqOrder_View>> InitGridHeader()
        {
            return new List<GridColumn<DqOrder_View>>{
                this.MakeGridHeader(x => x.factoryCode),
                this.MakeGridHeader(x => x.lineCode),
                this.MakeGridHeader(x => x.lineName),
                this.MakeGridHeader(x => x.scheduleNumber),
                this.MakeGridHeader(x => x.startTime),
                this.MakeGridHeader(x => x.endTime),
                this.MakeGridHeader(x => x.orderCode),
                this.MakeGridHeader(x => x.orderQty),
                this.MakeGridHeader(x => x.orderType),
                this.MakeGridHeader(x => x.orderStatus),
                this.MakeGridHeader(x => x.orderStateCode),
                this.MakeGridHeader(x => x.orderStartTime),
                this.MakeGridHeader(x => x.orderEndTime),
                this.MakeGridHeader(x => x.scheduleCode),
                this.MakeGridHeader(x => x.scheduleQty),
                this.MakeGridHeader(x => x.scheduleStatus),
                this.MakeGridHeader(x => x.scheduleStateCode),
                this.MakeGridHeader(x => x.scheduleStartTime),
                this.MakeGridHeader(x => x.scheduleEndTime),
                this.MakeGridHeader(x => x.productCode),
                this.MakeGridHeader(x => x.productName),
                this.MakeGridHeader(x => x.productVersion),
                this.MakeGridHeader(x => x.materialCode),
                this.MakeGridHeader(x => x.materialName),
                this.MakeGridHeader(x => x.materialVersion),
                this.MakeGridHeader(x => x.routeCode),
                this.MakeGridHeader(x => x.routeName),
                this.MakeGridHeader(x => x.routeVersion),
                this.MakeGridHeader(x => x.priority),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<DqOrder_View> GetSearchQuery()
        {
            var query = DC.Set<DqOrder>()
                .CheckContain(Searcher.scheduleNumber, x=>x.scheduleNumber)
                .CheckContain(Searcher.orderCode, x=>x.orderCode)
                .CheckContain(Searcher.orderStatus, x=>x.orderStatus)
                .CheckContain(Searcher.orderStateCode, x=>x.orderStateCode)
                .CheckContain(Searcher.scheduleCode, x=>x.scheduleCode)
                .CheckContain(Searcher.scheduleStatus, x=>x.scheduleStatus)
                .CheckContain(Searcher.scheduleStateCode, x=>x.scheduleStateCode)
                .CheckContain(Searcher.productCode, x=>x.productCode)
                .CheckContain(Searcher.productName, x=>x.productName)
                .CheckContain(Searcher.materialCode, x=>x.materialCode)
                .CheckContain(Searcher.routeCode, x=>x.routeCode)
                .CheckContain(Searcher.routeName, x=>x.routeName)
                .Select(x => new DqOrder_View
                {
				    ID = x.ID,
                    factoryCode = x.factoryCode,
                    lineCode = x.lineCode,
                    lineName = x.lineName,
                    scheduleNumber = x.scheduleNumber,
                    startTime = x.startTime,
                    endTime = x.endTime,
                    orderCode = x.orderCode,
                    orderQty = x.orderQty,
                    orderType = x.orderType,
                    orderStatus = x.orderStatus,
                    orderStateCode = x.orderStateCode,
                    orderStartTime = x.orderStartTime,
                    orderEndTime = x.orderEndTime,
                    scheduleCode = x.scheduleCode,
                    scheduleQty = x.scheduleQty,
                    scheduleStatus = x.scheduleStatus,
                    scheduleStateCode = x.scheduleStateCode,
                    scheduleStartTime = x.scheduleStartTime,
                    scheduleEndTime = x.scheduleEndTime,
                    productCode = x.productCode,
                    productName = x.productName,
                    productVersion = x.productVersion,
                    materialCode = x.materialCode,
                    materialName = x.materialName,
                    materialVersion = x.materialVersion,
                    routeCode = x.routeCode,
                    routeName = x.routeName,
                    routeVersion = x.routeVersion,
                    priority = x.priority,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class DqOrder_View : DqOrder{

    }
}
